//
// google_reader.hpp
//
// Library: SocialBox
// Package: 
// Module:  google_reader
//
// Definition of the GoogleReader class.
//
// Copyright (c) 2007, Bertrand Cachet and Contributors.
//
//

#ifndef SOCIALBOX_GOOGLE_READER_HPP
#define SOCIALBOX_GOOGLE_READER_HPP

/****************************************************
*       Forward declaration
****************************************************/

/****************************************************
*       STD dependencies
****************************************************/
#include <string>
#include <iosfwd> // Forward declaration of iostream


/****************************************************
*       POCO dependencies
****************************************************/
#include <Poco/HashMap.h>

/****************************************************
*       SociaBox dependencies
****************************************************/
#include "web_client.hpp"


class Result
{
public:
    Result();
    virtual ~Result();
    int status;
};


/****************************************************
*       GoogleReaderFeed class declatation
****************************************************/

class GoogleReaderFeed : public Result
{
public:
    GoogleReaderFeed();
    GoogleReaderFeed(std::string xmlData);
};

/****************************************************
*       GoogleReader class declatation
****************************************************/

class GoogleReader
{
private:
    WebClient* _webClient;
    std::string _username;
    std::string _password;
    Poco::HashMap<std::string, std::ostream*> *_buffers;
    Poco::HashMap<std::string, Result*> *_results;

    int _parseLogin(std::istream *data);

public:
    GoogleReader(std::string username="", std::string password="",
                 WebClient::SynchronizationMode mode=WebClient::Asynchronous);
    // We declare it explicit to prevent constructor to be called implicitly like conversion
    // Example: 
    // The following method: void f(GoogleReader gr)
    // if we do f(WebClient::Asynchronous) then it will call implicitly the GoogleReader constructor 
    // to perform conversion. 
    // This is not the case if we declare the constructor as explicit.
    explicit GoogleReader(const WebClient::SynchronizationMode mode=WebClient::Asynchronous);
    virtual ~GoogleReader();
    int login();
    int login(const std::string username, const std::string password);
    int getSubscriptionList();
    std::string getUsername();
    std::string getPassword();
    void setUsername(const std::string username);
    void setPassword(const std::string password);

private:
    static std::string ROOT_URL;
    static std::string LOGIN_URL;
    static std::string SOURCE;
private:
    DISALLOW_COPY_AND_ASSIGN(GoogleReader);
};

#endif // SOCIALBOX_GOOGLE_READER_HPP
